
clear 
include "$CODE/pathnames"

* Ensure Stata looks in the local ado folder first
adopath ++ "`c(pwd)'/ado"
* Verify ado path order
adopath

********************************************************************************
**** Table C1: Allocation of Treatment Questions to Protest Participants by Data Source

use "$DATA/data_list_experiment_final.dta", clear
tab Referer group_1 if sample_part

********************************************************************************
**** Table C2: Summary Statistics and Balance on Covariates for List Experiment

use "$DATA/data_list_experiment_final.dta", clear
global opt="sample_part==1"

outreg2 using "$REPLICATION/Tables_Appendix/Table_C2.xls" if $opt, replace sum(log) label excel keep(sex age moscow stpeter comm soclst yabl unrus savvy educ_3 educ_4 educ_5 educ_6 income_2 income_3 income_4 income_5 income_6 job_2 job_3 job_4 job_6 job_10 job_11 ) eqkeep(N mean sd)

bysort group_1: outreg2 using "$REPLICATION/Tables_Appendix/Table_C2.xls" if $opt, append sum(log) label keep(sex age moscow stpeter educ_3 educ_4 educ_5 educ_6 income_2 income_3 income_4 income_5 income_6 job_2 job_3 job_4 job_6 job_10 job_11 ) eqkeep(N mean)

#d ;
local sumstat sex age moscow stpeter comm soclst yabl unrus savvy 
		educ_3 educ_4 educ_5 educ_6 income_2 income_3 income_4 income_5 income_6 
		job_2 job_3 job_4 job_6 job_10 job_11  ;
foreach var of local sumstat { ;
	qui xi: reg `var' i.group_1 i.Referer if $opt & (group_1 == 1 | group_1==4), r ;
	qui test _Igroup_1_1 = 0 ;
	display r(p) ;
} ;
foreach var of local sumstat { ;
	qui xi: reg `var' i.group_1 i.Referer if $opt & (group_1 == 2 | group_1==4), r ;
	qui test _Igroup_1_2 = 0 ;
	display r(p) ;
} ;
foreach var of local sumstat { ;
	qui xi: reg `var' i.group_1 i.Referer if $opt & (group_1 == 3 | group_1==4), r ;
	qui test _Igroup_1_3 = 0 ;
	display r(p) ;
} ;
#d cr

********************************************************************************
**** Table C3: Blair and Imai (2012) Test of the `No Design Effect' Assumption

cd "$PROJ"
rscript using "$CODE/table_c3.R"

********************************************************************************
**** Table C4: List Experiment Estimates for Peer Pressure in Protest Participation

use "$DATA/data_list_experiment_final.dta", clear

local opt="replace"
global opt="sample_part==1"
global outtable="$REPLICATION/Tables_Appendix/Table_C4.xls"

global control0=""
global control1="$control0 i.moscow i.stpeter i.income"
global control2="$control1 i.Referer"
global control3="$control2 i.job"
global control4="$control3 i.sex age agesq i.educ"

foreach control in "control0" "control1" "control2" "control3" "control4" {
	xi: reg v16_1 i.group_1 $`control' if $opt, r
	if regexm("`control'","1|2|3|4") {
		testparm _Imoscow_1 _Istpeter_1
		local fedyes="Yes"
		if (r(p)<0.1) {
			local fedyes="Yes*"
		}
		if (r(p)<0.05) {
			local fedyes="Yes**"
		}
		if (r(p)<0.01) {
			local fedyes="Yes***"
		}
		testparm _Iincome*
		local incyes="Yes"
		if (r(p)<0.1) {
			local incyes="Yes*"
		}
		if (r(p)<0.05) {
			local incyes="Yes**"
		}
		if (r(p)<0.01) {
			local incyes="Yes***"
		}
	}
	if regexm("`control'","3|4") {
		testparm _Ijob*
		local occyes="Yes"
		if (r(p)<0.1) {
			local occyes="Yes*"
		}
		if (r(p)<0.05) {
			local occyes="Yes**"
		}
		if (r(p)<0.01) {
			local occyes="Yes***"
		}
		}
	if regexm("`control'","4") {
		testparm _Isex*
		local sexyes="Yes"
		if (r(p)<0.1) {
			local sexyes="Yes*"
		}
		if (r(p)<0.05) {
			local sexyes="Yes**"
		}
		if (r(p)<0.01) {
			local sexyes="Yes***"
		}
		testparm age*
		local ageyes="Yes"
		if (r(p)<0.1) {
			local ageyes="Yes*"
		}
		if (r(p)<0.05) {
			local ageyes="Yes**"
		}
		if (r(p)<0.01) {
			local ageyes="Yes***"
		}
		testparm _Ieduc*
		local eduyes="Yes"
		if (r(p)<0.1) {
			local eduyes="Yes*"
		}
		if (r(p)<0.05) {
			local eduyes="Yes**"
		}
		if (r(p)<0.01) {
			local eduyes="Yes***"
		}
	}
	lab var _Igroup_1_1 "Treatment Q1: Many of my friends and acquaintances participate"
	lab var _Igroup_1_3 "Treatment Q2: I wanted to tell friends and acquaintances about it"
	lab var _Igroup_1_2 "Treatment Q3: I wanted to tell about it in social media"
	if regexm("`control'","2|3|4|5") {	
		lab var _IReferer_2 "Forbes dummy"
		lab var _IReferer_3 "Panel dummy"
	}
	if regexm("`control'","0") {
		outreg2 using "$outtable", bracket keep(_Igroup*) `opt' label dec(3) nocons
	}
	else if regexm("`control'","1") {
		outreg2 using "$outtable", bracket keep(_Igroup*) `opt' label dec(3) addtext("Federal district FE", "`fedyes'", ///
			"Income level FE", "`incyes'") nocons
	}
	else if regexm("`control'","2") {
		outreg2 using "$outtable", bracket keep(_Igroup* _IReferer_2 _IReferer_3) `opt' label dec(3) addtext("Federal district FE", ///
			"`fedyes'", "Income level FE", "`incyes'") nocons
	}
	else if regexm("`control'","3") {
		outreg2 using "$outtable", bracket keep(_Igroup* _IReferer_2 _IReferer_3) `opt' label dec(3) addtext("Federal district FE", ///
			"`fedyes'", "Income level FE", "`incyes'", "Occupation FE", "`occyes'") nocons
	}
	else if regexm("`control'","4") {
		outreg2 using "$outtable", bracket keep(_Igroup* _IReferer_2 _IReferer_3) `opt' label dec(3) addtext("Federal district FE", ///
			"`fedyes'", "Income level FE", "`incyes'", "Occupation FE", "`occyes'", "Sex FE", ///
			"`sexyes'", "Age FE", "`ageyes'", "Education FE", "`eduyes'") nocons
	}
	local opt="append"
}

********************************************************************************
**** Table D1: Summary Statistics for City-Level Data

use "$DATA/data_crosscity_analysis_final.dta", clear

#d ;
fsum logprot dumprot logoldprot dumoldprot loggroup logvk logok2014 logspbsu2 logspbsu1 logspbsu3
		ip_2011 pop ac city2 dp dm logwage11 *y2010 educ2002 he2010_A20_24 
		he2010_A25_29 he2010_A30_34 he2010_A35_39 he2010_A40_44	he2010_A45_49 he2010_A50_more 
		University_exists ef2010 if sample, stat(n min median mean sd max) ;
#d cr 

fsum ln_consumerscooperatives ln_NGO sc_trust if sample & pop>50, stat(n min median mean sd max) 

********************************************************************************
**** Table D2: VK Online Protest Groups and Protest Participation (Second Week of Protests)

use "$DATA/data_crosscity_analysis_final.dta", clear

local opt="replace"
global outtable="$REPLICATION/Tables_Appendix/Table_D2.xls"
global ivregtype="ivreg2"
global err="cluster(okato_reg)"
global SPcohortsnoDurov="logspbsu1 logspbsu3"
#d ;
global control_pop="pop pop_2 pop_3 pop_4 pop_5 " ;
global control0="" ;
global control1="" ;
global control2="$control_pop  ac " ;
global control3="$control2 dp dm city2 logwage11 lA20_24_y2010 lA25_29_y2010 
		lA30_34_y2010 lA35_39_y2010  lA40_44_y2010 lA45_49_y2010 lA50_more_y2010 he2010_A20_24 
		he2010_A25_29 he2010_A30_34 he2010_A35_39 he2010_A40_44 he2010_A45_49 he2010_A50_more" ;
global control4="$control3 University_exists educ2002 ip_2011 logok2014 ef2010" ;
#d cr

// lists with controls for elections from different years as control5-control7
local controlall=""
forval i=5/7 {
	local y=95+(`i'-5)*4
	local y=`y'-int(`y'/100)*100
	local t="0`y'"
	local t=regexr("`t'","09","9")
	global control`i'="$control4 yabloko_`t' communists_`t' statusquo_`t' ldpr_`t' turnout_`t' against_`t'"
	global controlres`i'="$controlres4 yabloko_`t' communists_`t' statusquo_`t' ldpr_`t' turnout_`t' against_`t'"
	local controlall="`controlall' yabloko_`t' communists_`t' statusquo_`t' ldpr_`t' turnout_`t' against_`t'"
}	


foreach depvar in logprot dumprot {
	foreach control in "control4" "control5" "control6" "control7" {
		local F0="0"
		di "$ivregtype $err $dif"
		$ivregtype `depvar'  (loggroup=logspbsu2) $SPcohortsnoDurov $`control' `oldprot'  if sample , $err
		local F0=e(widstat)
		weakivtest
		local F0=r(F_eff)
		
		test pop=pop_2=pop_3=pop_4=pop_5=0
		local F1=r(p)
		local popyes="Yes"
		if (r(p)<0.01) {
			local popyes="Yes***"
		}	
		else if (r(p)<0.05) {
			local popyes="Yes**"
		}	
		else if (r(p)<0.1) {
			local popyes="Yes*"
		}	
	
		local F2="-1"
		test lA50_more_y2010+lA45_49_y2010 +lA40_44_y2010 +lA35_39_y2010+lA30_34_y2010+lA25_29_y2010+lA20_24_y2010 =0
		local F2=r(p)
		local ageyes="Yes"
		if (r(p)<0.01) {
			local ageyes="Yes***"
		}	
		else if (r(p)<0.05) {
			local ageyes="Yes**"
		}	
		else if (r(p)<0.1) {
			local ageyes="Yes*"
		}
		
		testparm he2010* educ*
		local F2=r(p)
		local heageyes="Yes"
		if (r(p)<0.01) {
			local heageyes="Yes***"
		}	
		else if (r(p)<0.05) {
			local heageyes="Yes**"
		}	
		else if (r(p)<0.1) {
			local heageyes="Yes*"
		}	

		local F3="-1"
		local i=regexr("`control'","control","")
		if regexm("`control'","5|6|7") {
			local y=95+(`i'-5)*4
			local y=`y'-int(`y'/100)*100
			local t="0`y'"
			local t=regexr("`t'","09","9")
			test yabloko_`t'=communists_`t'=statusquo_`t'=ldpr_`t'=turnout_`t'=against_`t'=0
			local F3=r(p)
			local elecyes="Yes"
			if (r(p)<0.01) {
				local elecyes="Yes***"
			}	
			else if (r(p)<0.05) {
				local elecyes="Yes**"
			}	
			else if (r(p)<0.1) {
				local elecyes="Yes*"
			}
		} 
		di "3"
		if regexm("`control'","4") {
			outreg2 using "$outtable", bracket drop(pop* lA* he* educ* yabloko* communists* statusquo* ldpr* turnout* against* ) addstat("Effective F-statistics",`F0')	`opt' label dec(3) nocons addtext("Population controls", "`popyes'","Age cohort controls","`ageyes'","Education controls","`heageyes'",`"Electoral controls, 1995"',"_",`"Electoral controls, 1999"',"_",`"Electoral controls, 2003"',"_") 
		}
		else if regexm("`control'","5") {
			outreg2 using "$outtable", bracket drop(pop* lA* he* educ* yabloko* communists* statusquo* ldpr* turnout* against* ) addstat("Effective F-statistics",`F0') `opt' label dec(3) nocons addtext("Population controls", "`popyes'","Age cohort controls","`ageyes'","Education controls","`heageyes'",`"Electoral controls, 1995"',"`elecyes'",`"Electoral controls, 1999"',"_",`"Electoral controls, 2003"',"_") 
		}
		else if regexm("`control'","6") {
			outreg2 using "$outtable", bracket drop(pop* lA* he* educ* yabloko* communists* statusquo* ldpr* turnout* against* )  addstat("Effective F-statistics",`F0') `opt' label dec(3) nocons addtext("Population controls", "`popyes'","Age cohort controls","`ageyes'","Education controls","`heageyes'",`"Electoral controls, 1995"',"_",`"Electoral controls, 1999"',"`elecyes'",`"Electoral controls, 2003"',"_") 
		}
		else {
			outreg2 using "$outtable", bracket drop(pop* lA* he* educ* yabloko* communists* statusquo* ldpr* turnout* against* ) addstat("Effective F-statistics",`F0') `opt' label dec(3) nocons addtext("Population controls", "`popyes'","Age cohort controls","`ageyes'","Education controls","`heageyes'",`"Electoral controls, 1995"',"_",`"Electoral controls, 1999"',"_",`"Electoral controls, 2003"',"`elecyes'") 
		}
	
		local opt="append"
	}
}

foreach depvar in logprot dumprot {
	foreach control in "control4" "control5" "control6" "control7" {
		qui $ivregtype `depvar'  (loggroup=logspbsu2) $SPcohortsnoDurov $`control' `oldprot' if sample  , $err
		qui weakiv, lm usegrid gridpoints(2000) gridmin(-5) gridmax(15)
		display e(ar_cset)
	}
}

** Chernozhukov and Hansen (2008)
set matsize 10000
preserve
keep if sample
foreach yvar in "logprot" "dumprot" {
	foreach control in "control4" "control5" "control6" "control7" {
		quietly {
			reg `yvar' $SPcohortsnoDurov $`control' if sample
			predict yh, res
			reg loggroup $SPcohortsnoDurov $`control' if sample
			predict xh, res
			reg logspbsu2 $SPcohortsnoDurov $`control' if sample
			predict zh, res
			global nrep = 2000
			matrix beta = J($nrep,1,1)
			matrix alpha = J($nrep,1,1)
			matrix var = J($nrep,1,1)
			matrix w_s = J($nrep,1,1)
			gen yhat = .
			* Go over a grid for b in [-10, 10]
			scalar b = -10
			forval i=1/$nrep {
				scalar b = b + 50/$nrep
				qui replace yhat = yh-xh*b
				qui reg yhat zh , nocons 
				matrix beta[`i',1] = b
				matrix alpha[`i',1] = _b[zh]
				matrix var[`i',1] = (_se[zh])^2
				matrix w_s[`i',1] = alpha[`i',1]^2 / var[`i',1]
			}
			svmat w_s, names(w_s)
			svmat beta, names(beta)
			gen ci = (w_s <= 3.84)
			sum beta if ci==1
		}
		display "(" r(min) ";" r(max) ")"
		drop w_s beta ci yh xh zh yhat
	}
}

** Mikusheva (2010)
foreach yvar in "logprot" "dumprot" {
	foreach control in "control4" "control5" "control6" "control7" { 
		qui reg `yvar' $SPcohortsnoDurov $`control' if sample
		qui predict yh, res
		qui reg loggroup $SPcohortsnoDurov $`control' if sample
		qui predict xh, res
		qui reg logspbsu2 $SPcohortsnoDurov $`control' if sample
		qui predict zh, res
		condivreg yh (xh = zh), liml interval
		qui drop yh xh zh
	}
}
restore

********************************************************************************
**** Table D3: VK Online Protest Groups and pre-VK Protests

use "$DATA/data_crosscity_analysis_final.dta", clear

global outtable="$REPLICATION/Tables_Appendix/Table_D3.xls"
global ivregtype="ivreg2"
global err="cluster(okato_reg)"
global SPcohortsnoDurov="logspbsu1 logspbsu3"
global control4="pop pop_2 pop_3 pop_4 pop_5 ac dp dm city2 logwage11 lA20_24_y2010 lA25_29_y2010 lA30_34_y2010 lA35_39_y2010  lA40_44_y2010 lA45_49_y2010 lA50_more_y2010 he2010_A20_24 he2010_A25_29 he2010_A30_34 he2010_A35_39 he2010_A40_44 he2010_A45_49 he2010_A50_more University_exists educ2002 ip_2011 logok2014 ef2010"
local controlall=""
forval i=5/7 {
	local y=95+(`i'-5)*4
	local y=`y'-int(`y'/100)*100
	local t="0`y'"
	local t=regexr("`t'","09","9")
	global control`i'="$control4 yabloko_`t' communists_`t' statusquo_`t' ldpr_`t' turnout_`t' against_`t'"
}	

* Panel A. Number of Participants
local opt="replace"
foreach depvar in logoldprot logoldprot_dem logmonprot log_Robertson_Total {
	local oldprot=""
	foreach control in "control4" "control5" "control6" "control7" {
			if regexm("`depvar'","dumprot") {
				local oldprot=""
			}	
			qui $ivregtype `depvar' (loggroup=logspbsu2) $SPcohortsnoDurov  $`control' `oldprot' if sample, $err
			outreg2 using "$outtable", bracket keep(loggroup) label dec(3) nocons noaster `opt'
			local opt="append"
		}	
}

* Panel B. Incidence
foreach depvar in dumoldprot dumoldprot_dem dummonprot dum_Robertson_Total {
	local oldprot=""
	foreach control in "control4" "control5" "control6" "control7" {
			if regexm("`depvar'","dumprot") {
				local oldprot=""
			}	
			qui $ivregtype `depvar' (loggroup=logspbsu2) $SPcohortsnoDurov  $`control' `oldprot' if sample, $err
			outreg2 using "$outtable", bracket keep(loggroup) label dec(3) nocons noaster `opt' 
			local opt="append"
		}	
}

********************************************************************************
**** Table D4: Dynamic VK Penetration Effect, 2011--2012. Panel IV. Separately for the First Two Weeks and Later.

use "$DATA/data_crosscity_analysis_final.dta", clear

global outtable="$REPLICATION/Tables_Appendix/Table_D4.xls"
global ivregtype="ivreg2"
global err="cluster(okato_reg)"
global SPcohortsnoDurov="logspbsu1 logspbsu3"
global control4="pop pop_2 pop_3 pop_4 pop_5 ac dp dm city2 logwage11 lA20_24_y2010 lA25_29_y2010 lA30_34_y2010 lA35_39_y2010  lA40_44_y2010 lA45_49_y2010 lA50_more_y2010 he2010_A20_24 he2010_A25_29 he2010_A30_34 he2010_A35_39 he2010_A40_44 he2010_A45_49 he2010_A50_more University_exists educ2002 ip_2011 logok2014 ef2010"
local controlall=""
forval i=5/7 {
	local y=95+(`i'-5)*4
	local y=`y'-int(`y'/100)*100
	local t="0`y'"
	local t=regexr("`t'","09","9")
	global control`i'="$control4 yabloko_`t' communists_`t' statusquo_`t' ldpr_`t' turnout_`t' against_`t'"
}	
local i=4
foreach varlist in "$control4" "$control5" "$control6" "$control7" {
	local tmp=""
	foreach var in `varlist' {
		local tmp="`tmp' `var'_t"
	}
	global timecontrol`i'="`tmp'"
	local i=`i'+1
}

local opt="replace"
xtset cityid week
foreach depvar in logprot dumprot {
	foreach time in  "t t2 t3 t4 t5" {
		foreach control in "timecontrol4" "timecontrol5" "timecontrol6" "timecontrol7" {
			xtivreg2 `depvar' logspbsu1_t logspbsu3_t $`control' logoldprot_t `time' (logvk_t = logspbsu2_t) if week_year<201151 , fe  $err 
			local FKP=e(widstat) 
			
			outreg2 using "$outtable", bracket drop(pop* lA* yabloko* communists* statusquo* ldpr* turnout* against* ) `opt' label dec(4) nocons addstat("K-P F-stat", `FKP') cttop("The first two weeks")
			local opt="append"
		}		
	}	
}

foreach depvar in logprot dumprot {
	foreach time in  "t t2 t3 t4 t5" {
		foreach control in "timecontrol4" "timecontrol5" "timecontrol6" "timecontrol7" {
			xtivreg2 `depvar' logspbsu1_t logspbsu3_t $`control' logoldprot_t `time' (logvk_t = logspbsu2_t) if week_year>=201150 &  week_year<201187, fe  $err 
			local FKP=e(widstat) 
			
			outreg2 using "$outtable", bracket drop(pop* lA* yabloko* communists* statusquo* ldpr* turnout* against* ) `opt' label dec(4) nocons addstat("K-P F-stat", `FKP') cttop("Starting the second week")
			local opt="append"
		}		
	}	
}

********************************************************************************
**** Table D5: Dynamic Association between Social Capital and Protests, 2011--2012. Separately for the First Two Weeks and Later

use "$DATA/data_crosscity_analysis_final.dta", clear
keep if pop>50

global outtable="$REPLICATION/Tables_Appendix/Table_D5.xls"
global ivregtype="ivreg2"
global err="cluster(okato_reg)"
global SPcohortsnoDurov="logspbsu1 logspbsu3"
global control4="pop pop_2 pop_3 pop_4 pop_5 logwage11 educ2002 educ ip_2011 ef2010"
local controlall=""
forval i=5/7 {
	local y=95+(`i'-5)*4
	local y=`y'-int(`y'/100)*100
	local t="0`y'"
	local t=regexr("`t'","09","9")
	global control`i'="$control4 yabloko_`t' communists_`t' statusquo_`t' ldpr_`t' turnout_`t' against_`t'"
}	
local i=4
foreach varlist in "$control4" "$control5" "$control6" "$control7" {
	local tmp=""
	foreach var in `varlist' {
		local tmp="`tmp' `var'_t"
	}
	global timecontrol`i'="`tmp'"
	local i=`i'+1
}
global time = "t t2 t3 t4 t5"

local opt="replace"
foreach depvar in logprot dumprot {
  foreach indepvar in ln_consumerscooperatives ln_NGO  sc_trust Social_cap_Katz  {
		foreach control in "timecontrol4" {
			reghdfe `depvar' `indepvar'_t  $`control' $time if week_year<201151 , a(OKATO) $err 
			outreg2 using "$outtable", bracket drop(pop* lA* yabloko* communists* statusquo* ldpr* turnout* against* $time ) ///
			`opt' label dec(4) nocons cttop("The first two weeks")

			local opt="append"
		}		
	}	
}	

foreach depvar in logprot dumprot {
  foreach indepvar in ln_consumerscooperatives ln_NGO  sc_trust Social_cap_Katz  {
		foreach control in "timecontrol4" {
			reghdfe `depvar' `indepvar'_t  $`control' $time if week_year>=201150 &  week_year<201187, a(OKATO) $err 
			outreg2 using "$outtable", bracket drop(pop* lA* yabloko* communists* statusquo* ldpr* turnout* against* $time ) ///
			`opt' label dec(4) nocons cttop("Starting the second week")
			local opt="append"
		}	
	}	
}

********************************************************************************
**** Table E1: Protest Participation and Social Capital (First Week of Protests)

use "$DATA/data_crosscity_analysis_final.dta", clear
keep if pop>50

global outtable="$REPLICATION/Tables_Appendix/Table_E1.xls"
global err="robust"
global control="pop pop_2 pop_3 pop_4 pop_5 logwage11 educ2002 educ ip_2011 ef2010"

local opt="replace"
foreach depvar in logprot dumprot {
  foreach indepvar in ln_consumerscooperatives ln_NGO  sc_trust Social_cap_Katz  {
		foreach control in "timecontrol4" {
			reg `depvar' `indepvar'  $control if sample , $err 
			outreg2 using "$outtable", bracket drop(pop*) `opt' label dec(4) nocons cttop("The first week")
			local opt="append"
		}		
	}	
}	

********************************************************************************
**** Table E2: Individual Trust and Protest Participation in 2011

use "$DATA/data_list_experiment_final.dta", clear

local opt="replace"
global outtable="$REPLICATION/Tables_Appendix/Table_E2.xls"

global control0=""
global control1="$control0 i.moscow i.stpeter i.income"
global control2="$control1 i.Referer"
global control3="$control2 i.job"
global control4="$control3 i.sex age agesq i.educ"

foreach control in "control0" "control1" "control2" "control3" "control4" {
	xi: reg dumprot trust $`control' dumgovprot, r
	if regexm("`control'","1|2|3|4") {
		testparm _Imoscow_1 _Istpeter_1
		local fedyes="Yes"
		if (r(p)<0.1) {
			local fedyes="Yes*"
		}
		if (r(p)<0.05) {
			local fedyes="Yes**"
		}
		if (r(p)<0.01) {
			local fedyes="Yes***"
		}
		testparm _Iincome*
		local incyes="Yes"
		if (r(p)<0.1) {
			local incyes="Yes*"
		}
		if (r(p)<0.05) {
			local incyes="Yes**"
		}
		if (r(p)<0.01) {
			local incyes="Yes***"
		}
	}
	if regexm("`control'","3|4") {
		testparm _Ijob*
		local occyes="Yes"
		if (r(p)<0.1) {
			local occyes="Yes*"
		}
		if (r(p)<0.05) {
			local occyes="Yes**"
		}
		if (r(p)<0.01) {
			local occyes="Yes***"
		}
		}
	if regexm("`control'","4") {
		testparm _Isex*
		local sexyes="Yes"
		if (r(p)<0.1) {
			local sexyes="Yes*"
		}
		if (r(p)<0.05) {
			local sexyes="Yes**"
		}
		if (r(p)<0.01) {
			local sexyes="Yes***"
		}
		testparm age*
		local ageyes="Yes"
		if (r(p)<0.1) {
			local ageyes="Yes*"
		}
		if (r(p)<0.05) {
			local ageyes="Yes**"
		}
		if (r(p)<0.01) {
			local ageyes="Yes***"
		}
		testparm _Ieduc*
		local eduyes="Yes"
		if (r(p)<0.1) {
			local eduyes="Yes*"
		}
		if (r(p)<0.05) {
			local eduyes="Yes**"
		}
		if (r(p)<0.01) {
			local eduyes="Yes***"
		}
	}
	if regexm("`control'","0") {
		outreg2 using "$outtable", bracket keep(trust) `opt' label dec(3) nocons
	}
	else if regexm("`control'","1") {
		outreg2 using "$outtable", bracket keep(trust) `opt' label dec(3) addtext("Federal district FE", "`fedyes'", ///
			"Income level FE", "`incyes'") nocons
	}
	else if regexm("`control'","2") {
		outreg2 using "$outtable", bracket keep(trust) `opt' label dec(3) addtext("Federal district FE", ///
			"`fedyes'", "Income level FE", "`incyes'") nocons
	}
	else if regexm("`control'","3") {
		outreg2 using "$outtable", bracket keep(trust) `opt' label dec(3) addtext("Federal district FE", ///
			"`fedyes'", "Income level FE", "`incyes'", "Occupation FE", "`occyes'") nocons
	}
	else if regexm("`control'","4") {
		outreg2 using "$outtable", bracket keep(trust) `opt' label dec(3) addtext("Federal district FE", ///
			"`fedyes'", "Income level FE", "`incyes'", "Occupation FE", "`occyes'", "Sex FE", ///
			"`sexyes'", "Age FE", "`ageyes'", "Education FE", "`eduyes'") nocons
	}
	local opt="append"
}
